import { setUserToken, resetUser } from './user'
import { setToken, removeToken } from '@/utils/auth'
import store from '@/store'

export const login = (username, password) => {
  return new Promise((resolve, reject) => {
    if (username.trim() !== 'admin' || password.trim() !== 'admin') {
      reject()
    }
    const token = 'admin-token'
    const data = {
      username: 'jikey'
    }
    store.dispatch(setUserToken(token))
    setToken(token)
    resolve(data)
  })
}

export const logout = token => {
  return new Promise((resolve, reject) => {
    const data = {
      username: 'jikey'
    }
    store.dispatch(resetUser())
    removeToken()
    resolve(data)
  })
}
